//-------------------------------------------------------------------
//	Copyright (c) 2010-2011  Zhirnov Andrey
//	This file is part of the "UXGEN_ResourceConverter" project.
//	See copyright notice in "Converter.h".
//-------------------------------------------------------------------

#ifndef _RC_SOUND_CONVERTER_H
#define _RC_SOUND_CONVERTER_H

#include "stdafx.h"

class CSoundConverter : public ISoundConverter
{
private:
	struct TSoundSrcInfo
	{
		const char	*pCodec;
		uint		uChannels,
					uBitrate,
					uFrequency,
					uBitPerSample,
					uSize;
		///
		TSoundSrcInfo(): pCodec(nullptr), uChannels(0), uBitrate(0), uFrequency(0), uBitPerSample(0), uSize(0) {}
	};

	typedef array< char, TFastCopyStrategy<char> >		sounddata_t;
	typedef void *PCodec_t(sounddata_t &aData, uint8 numChannels, uint bitsPerSample, float sampleFrequency);
	
private:
	TSoundParams			_sParams;
	TSoundSrcInfo			_sInfo;
	e_sound_format::type	_eFormat;
	binary_buffer_t			_aSoundData;
	
	bool _LoadPCM(IFilePtr pFile);
	bool _LoadWAV(IFilePtr pFile);
	bool _LoadOGG(IFilePtr pFile);
	bool _SaveSND(IFilePtr pFile);

public:
	CSoundConverter();
	~CSoundConverter();

	// ISoundConverter //
	HRESULT CALLBACK GetSupportedFormats(char *pBuffer, uint uCount);

	HRESULT CALLBACK Load(const char *pcFileName);
	HRESULT CALLBACK Save(const char *pcFileName);
	HRESULT CALLBACK Delete();

	HRESULT CALLBACK SetParams(const TSoundParams &sParams);
	HRESULT CALLBACK GetParams(TSoundParams &sParams);

	HRESULT CALLBACK GetInfo(char *pBuffer, uint uCount);
	
	// ISubSystem //
	HRESULT CALLBACK GetType(E_SUBSYSTEM_TYPE &eType);
	
	IBASE_IMPLEMENTATION( ISoundConverter )
};

#endif	// _RC_SOUND_CONVERTER_H
